Skip to content

gh-154892: Fix PyLong_AsLong() error checks in _zoneinfo - #154901

Open
BHUVANSH855 wants to merge 2 commits into
python:mainfrom
BHUVANSH855:fix-zoneinfo-minus-one
Open

gh-154892: Fix PyLong_AsLong() error checks in _zoneinfo#154901
BHUVANSH855 wants to merge 2 commits into
python:mainfrom
BHUVANSH855:fix-zoneinfo-minus-one

Conversation

@BHUVANSH855

Copy link
Copy Markdown
Contributor

Summary

Fix Modules/_zoneinfo.c:get_local_timestamp() to correctly distinguish a legitimate -1 result from PyLong_AsLong() from an actual conversion error by checking PyErr_Occurred(), matching the documented C API behavior and the pure-Python implementation.

The previous implementation treated any -1 return value from PyLong_AsLong() as an error, even when no exception was set. This caused datetime subclasses overriding hour, minute, or second to return -1 to incorrectly raise an exception in the C accelerator.

This PR also adds a regression test covering datetime subclasses whose hour, minute, and second properties return -1.

Issue

Closes: gh-154892

Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py Outdated
Comment thread Modules/_zoneinfo.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_zoneinfo: get_local_timestamp() misinterprets valid -1 results from PyLong_AsLong()

2 participants